package com.mopeso;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Handler;
import android.widget.Toast;

import com.mopeso.Utils.DebugUtil;

public class LaunchActivity extends BaseActivity {

    @Override
    protected int getContentViewId() {
        return R.layout.activity_launch;
    }

    @Override
    public void onBindView() {

    }

    @Override
    protected void onResume() {
        super.onResume();
        boolean connected = isNetworkAvailable(this);
        if (!connected) {
            String tip = "Network exception, please check and try again";
            Toast.makeText(this, tip, Toast.LENGTH_LONG).show();
            return;
        }
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                startActivity(new Intent(LaunchActivity.this, MainActivity.class));
                LaunchActivity.this.finish();
            }
        }, 2000);
    }

    @Override
    public void initData() {}

    public boolean isNetworkAvailable(Context context) {
        boolean hasWifiConnect = false;
        boolean hasMobileConnect = false;
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo[] netInfo = cm.getAllNetworkInfo();
        for (NetworkInfo net : netInfo) {
            String type = net.getTypeName();
            if (type.equalsIgnoreCase("WIFI")) {
                if (net.isConnected()) {
                    hasWifiConnect = true;
                }
            }
            if (type.equalsIgnoreCase("MOBILE")) {
                if (net.isConnected()) {
                    hasMobileConnect = true;
                }
            }
        }
        return hasWifiConnect || hasMobileConnect;

    }
}